package com.evil.enterprise.controller;

import com.evil.application.api.RemoteApplicationRobotService;
import com.evil.application.pojo.dto.robot.*;
import com.evil.common.core.entity.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 机器人接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/application/robot")
public class ApplicationRobotController {

    private final RemoteApplicationRobotService remoteApplicationRobotService;

    /**
     * 应用机器人列表
     *
     * @param applicationRobotsReqDTO applicationRobotsReqDTO
     * @return R
     */
    @PostMapping("/list")
    public R<List<ApplicationRobotRespDTO>> applicationRobots(@Validated @RequestBody ApplicationRobotsReqDTO applicationRobotsReqDTO) {
        return R.success(remoteApplicationRobotService.applicationRobots(applicationRobotsReqDTO));
    }

    /**
     * 应用机器人详情
     *
     * @param robotId robotId
     * @return R
     */
    @PostMapping("/info")
    public R<ApplicationRobotRespDTO> applicationRobotInfo(@RequestParam("robotId") @NotNull(message = "机器人id不能为空") Long robotId) {
        return R.success(remoteApplicationRobotService.applicationRobotInfo(robotId));
    }

    /**
     * 添加应用机器人
     *
     * @param addApplicationRobotReqDTO addApplicationRobotReqDTO
     * @return R
     */
    @PostMapping("/add")
    public R<?> addApplicationRobot(@Validated @RequestBody AddApplicationRobotReqDTO addApplicationRobotReqDTO) {
        remoteApplicationRobotService.addApplicationRobot(addApplicationRobotReqDTO);
        return R.success();
    }

    /**
     * 编辑应用机器人
     *
     * @param modifyApplicationRobotReqDTO modifyApplicationRobotReqDTO
     * @return R
     */
    @PostMapping("/modify")
    public R<?> modifyApplicationRobot(@Validated @RequestBody ModifyApplicationRobotReqDTO modifyApplicationRobotReqDTO) {
        remoteApplicationRobotService.modifyApplicationRobot(modifyApplicationRobotReqDTO);
        return R.success();
    }

    /**
     * 复制应用机器人
     *
     * @param robotId robotId
     * @return R
     */
    @PostMapping("/copy")
    public R<?> copyApplicationRobot(@RequestParam("robotId") @NotNull(message = "机器人id不能为空") Long robotId) {
        remoteApplicationRobotService.copyApplicationRobot(robotId);
        return R.success();
    }

    /**
     * 编辑应用机器人状态
     *
     * @param modifyAppRobotStatusReqDTO modifyAppRobotStatusReqDTO
     * @return R
     */
    @PostMapping("/modify/status")
    public R<?> modifyApplicationRobotStatus(@Validated @RequestBody ModifyAppRobotStatusReqDTO modifyAppRobotStatusReqDTO) {
        remoteApplicationRobotService.modifyApplicationRobotStatus(modifyAppRobotStatusReqDTO);
        return R.success();
    }

    /**
     * 删除机器人
     *
     * @param robotId robotId
     * @return R
     */
    @PostMapping("/delete")
    public R<?> deleteApplicationRobot(@RequestParam("robotId") @NotNull(message = "机器人id不能为空") Long robotId) {
        remoteApplicationRobotService.deleteApplicationRobot(robotId);
        return R.success();
    }
}
